package com.codingfuture.erp_system.service.impl;

import com.codingfuture.erp_system.dto.OrdersDetailDto;
import com.codingfuture.erp_system.dto.OrdersDto;
import com.codingfuture.erp_system.entity.Orders;
import com.codingfuture.erp_system.entity.Role;
import com.codingfuture.erp_system.entity.Supplier;
import com.codingfuture.erp_system.mapper.OrdersMapper;
import com.codingfuture.erp_system.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public List<Orders> findByAll(Orders orders) {
        return ordersMapper.findByAll(orders);
    }

    @Override
    public List<OrdersDetailDto> findOrdersDetailDto(long uuid) {
        return ordersMapper.findOrdersDetailDto(uuid);
    }

    @Override
    public List<Supplier> showSupplier(Integer type) {
        return ordersMapper.showSupplier(type);
    }

    @Override
    public List<OrdersDetailDto> findByOrders() {
        return ordersMapper.findByOrders();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addOrders(Orders orders, OrdersDetailDto ordersDetailList) {
        return ordersMapper.addOrders(ordersDetailList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean doStart(Integer id, Date date) {
        return ordersMapper.doStart(id, date);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean doCheck(Integer id, Date date) {
        return ordersMapper.doCheck(id, date);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addOrdersDetail(List<OrdersDetailDto> ordersDetails) {
        return ordersMapper.addOrdersDetail(ordersDetails);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addById(OrdersDto ordersDto) {
        return ordersMapper.addById(ordersDto);
    }

    @Override
    public Role findByName(Object name) {
        return ordersMapper.findByName(name);
    }

}
